package lendingbooks.copy;

import java.util.ArrayList;
import java.util.Collection;

import lendingbooks.activities.R;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class FriendCopyListAdapter extends ArrayAdapter<CopyListViewRow> {

	protected ArrayList<CopyListViewRow> _Items;
	
	public FriendCopyListAdapter(Context context, 
								int textViewResourceId,
								ArrayList<CopyListViewRow> p_items) {
		super(context, textViewResourceId, p_items);
		_Items = p_items;
	}	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
        	LayoutInflater vi = LayoutInflater.from(getContext());
            v = vi.inflate(R.layout.list_friend_copy_row, null);
        }
        CopyListViewRow copyListViewRow = _Items.get(position); 
        if (copyListViewRow != null) {
        	((TextView)v.findViewById(R.id.list_copy_row_title)).setText(copyListViewRow.getCopy().getTitle());
        	
        	((TextView)v.findViewById(R.id.list_copy_row_friend)).setText(copyListViewRow.getCopy().firstName +" " +copyListViewRow.getCopy().lastName);
        	Integer rate = copyListViewRow.getCopy().getRate();
        	rate = rate==null?0:rate;
        	((RatingBar)v.findViewById(R.id.list_copy_row_rating)).setRating((float)rate);
        }
        return v;
	}
	
}
